package com.hengtiansoft.lfy.net;

import android.content.Context;
import android.util.Log;

import com.hengtiansoft.lfy.R;
import com.hengtiansoft.lfy.constants.Constants;
import com.hengtiansoft.lfy.entity.EvaluatorMessageEntity;
import com.hengtiansoft.lfy.entity.EvaluatorModeEntity;
import com.hengtiansoft.lfy.entity.EvaluatorRankings;
import com.hengtiansoft.lfy.entity.ServiceResult;
import com.hengtiansoft.lfy.utils.Config;
import com.hengtiansoft.lfy.utils.ScreenUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by daiye on 2016/10/25 0025.
 */

public class NetHelper {
    /**
     * 获取用户信息
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void userLogin(Context context, String username, String screPassword, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("loginname", username);
        map.put("password", screPassword);
        NetUtils.post(context, Constants.LOGIN_URL, map, context.getString(R.string.network_login), netCallBack, rspCls);
    }

    /**
     * 用户注册
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void otherUserRegister(Context context,String openid, String type,String nickname,String headimg,String gender, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("id", openid);
        map.put("nickname", nickname);
        map.put("imagepath", headimg);
        map.put("type", type);
        map.put("sex", gender);
        NetUtils.post(context, Constants.RegisterOtherUser, map, context.getString(R.string.network_register), netCallBack, rspCls);
    }

    /**
     * 用户注册
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void userRegister(Context context,String username, String screPassword, String telphone, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("username", username);
        map.put("password", screPassword);
        map.put("telphone", telphone);
        NetUtils.post(context, Constants.RegisterUser_URL, map, context.getString(R.string.network_register), netCallBack, rspCls);
    }

    /**
     * 电话信息修改
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void modifyUserMobile(Context context, String username, String telphone, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("token", Config.getUserToken());
        map.put("username", username);
        map.put("telphone", telphone);
        NetUtils.post(context, Constants.UpdateUserPhone, map, context.getString(R.string.network_register), netCallBack, rspCls);
    }

    /**
     * 获取token
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void getUserToken(Context context, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("mID", ScreenUtils.getIMEI(context));
        map.put("mVersion", ScreenUtils.getVersion(context));
        map.put("mType", ScreenUtils.getMobileModelInfo());
        map.put("mWidth", ScreenUtils.getScreenWidth(context));
        map.put("mHeight", ScreenUtils.getScreenHeight(context));
        NetUtils.post(context, Constants.GETTOKEN_URL, map, null, netCallBack, rspCls);
    }

    /**
     * 获取用户信息
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void getUserServerInfo(Context context, String username, String screPassword, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("token", Config.getUserToken());
        map.put("username", username);
        map.put("password", screPassword);
        NetUtils.post(context, Constants.getUserByUsername, map, null, netCallBack, rspCls);
    }

    /**
     * 用户密码修改
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void userPasswordChange(Context context, String code, String telephone, String screPassword, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("code", code);
        map.put("telphone", telephone);
        map.put("password", screPassword);
        NetUtils.post(context, Constants.ForgetPassword, map, null, netCallBack, rspCls);
    }

    /**
     * 更新密码
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void UpdateUserPassword(Context context,String screPassword,String newpassword, final NetUtils.NetCallBack<ServiceResult> netCallBack, final Class<?> rspCls) {
        HashMap map = new HashMap();
        map.put("username", Config.getUserName());
        map.put("password", screPassword);
        map.put("newpassword",newpassword);
        map.put("token", Config.getUserToken());
        NetUtils.post(context, Constants.UpdateUserPassword_TEMP, map, null, netCallBack, rspCls);
    }
    /**
     * 获取新闻
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void getNewsList(Context context, int page, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("had_push", "1");
        map.put("page",String.valueOf(page));
        map.put("pagesize",String.valueOf(Constants.PAGE_SIZE));
        NetUtils.post(context,  Constants.SERVER_HOST + "getNewsList", map, null, netCallBack, rspCls);
    }

    /**
     * 收藏翻译历史
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void collect(Context context, int mode, String src, String translate, String serverId, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        if( mode == 0){
            map.put("token", Config.getUserToken());
            map.put("username", Config.getUserName());
            map.put("src_content",src);
            map.put("des_content",translate);
            NetUtils.post(context,  Constants.AddCollect , map, null, netCallBack, rspCls);
        }else{
            map.put("token", Config.getUserToken());
            map.put("collectid",serverId);
            NetUtils.post(context,  Constants.DeleteCollect , map, null, netCallBack, rspCls);
        }
    }
    /**
     * 获取测评试题
     *
     * @param context
     * @param netCallBack
     */
    public static void getEvaluatorMode(Context context, final NetUtils.NetCallBack<List<EvaluatorModeEntity>> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        NetUtils.jsonPostEvMode(context, netCallBack, Constants.SERVER_HOST_EX + "getExamPaperList", map, null);
    }
    /**
     * 获取测评试题具体内容
     * @param context
     * @param netCallBack
     */
    public static void getEvaluator(Context context, int paperId, final NetUtils.NetCallBack<List<EvaluatorMessageEntity>> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("paperserial",paperId+"");
        NetUtils.jsonPostEv(context, netCallBack, Constants.SERVER_HOST_EX + "getExamSubjectList", map, null);
    }

    /**
     * 上传已完成试卷内容，获取今日排名
     * @param context
     * @param netCallBack
     */
    public static void uploadExerciseFinished(Context context, String paperId,String score, String remark,final NetUtils.NetCallBack<EvaluatorRankings> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("paperserial",paperId);
        map.put("username", Config.getUserName());
        map.put("score", score);
        map.put("usedsecs", "0");
        map.put("remark", remark);
        NetUtils.jsonPostExercise(context, netCallBack, Constants.SERVER_HOST_EX + "kaoshi", map, null);
    }
    /**
     * 查询用户口语力总成绩（实际是平均成绩），总练习时长，今日时长，总分排名比例接口
     * @param context
     * @param netCallBack
     */
    public static void getTotalScore(Context context,final NetUtils.NetCallBack<EvaluatorRankings> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("username", Config.getUserName());
        NetUtils.jsonPostExercise(context, netCallBack, Constants.SERVER_HOST_EX + "ChaXun", map, null);
    }

    /**
     * 上传练习时长
     * @param context
     * @param netCallBack
     */
    public static void uploadExerciseTime(Context context,String time,final NetUtils.NetCallBack<EvaluatorRankings> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("username", Config.getUserName());
        map.put("time",time);
        NetUtils.jsonPostExercise(context, netCallBack, Constants.SERVER_HOST_EX + "ShiChang", map, null);
    }

    /**
     * 获取已完成试题列表
     * @param context
     * @param netCallBack
     */
    public static void getCompleteHistory(Context context,final NetUtils.NetCallBack<List<EvaluatorModeEntity>> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("username", Config.getUserName());
        NetUtils.jsonPostExerciseHistory(context, netCallBack, Constants.SERVER_HOST_EX + "queryMessage", map, null);
    }
    /**
     * 获取已完成试题内容
     * @param context
     * @param netCallBack
     */
    public static void getCompleteItem(Context context,String paperSerial,final NetUtils.NetCallBack<String> netCallBack) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("username", Config.getUserName());
        map.put("paperserial", paperSerial);
        NetUtils.jsonPostExerciseitem(context, netCallBack, Constants.SERVER_HOST_EX + "getExamHis", map, null);
    }
    /**
     * 获取场景
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void getchildCategroyFromServer(Context context,String category, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("category", category);
        NetUtils.post(context,  Constants.SERVER_HOST + "getScenesList", map, null, netCallBack, rspCls);
    }

    /**
     * 获取场景分类
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void getchild_TypeCategroyFromServer(Context context,String scenesid, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("scenesid", scenesid);
        NetUtils.post(context,  Constants.SERVER_HOST + "getScenesList", map, null, netCallBack, rspCls);
    }

    /***
     * 获取场景详细
     * @param context
     * @param scenesid
     * @param netCallBack
     * @param rspCls
     */
    public static void getWordsCategroyFromServer(Context context,String scenesid, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("scenesid", scenesid);
        NetUtils.post(context,  Constants.SERVER_HOST + "getScenesDetailList", map, null, netCallBack, rspCls);
    }

    /***
     * 取消网络收藏
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void deletecollectRequest(Context context,String token,String collectid,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("token", token);
        map.put("collectid",collectid);
        NetUtils.post(context,  Constants.SERVER_HOST + "DeleteCollect/", map, null, netCallBack, rspCls);
    }
    /***
     * 添加网络收藏
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void collection(Context context,String token,String src_content,String des_content,String username,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("token", token);
        map.put("src_content",src_content);
        map.put("des_content",des_content);
        map.put("username",username);
        NetUtils.post(context,  Constants.SERVER_HOST + "AddCollect/", map, null, netCallBack, rspCls);
    }

    /***
     * 是否显示产品介绍
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void isShowRequest(Context context, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        NetUtils.get(context,  Constants.SERVER_HOST + "guidePhoto", null, netCallBack, rspCls);
    }

    public static void updateApi(Context context,String version,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("version", version);
        NetUtils.post(context,  Constants.SERVER_HOST + "updateApk/", map, null, netCallBack, rspCls);
    }

    /***
     * 反馈
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void feedback(Context context,String content,String phonetype,String systemtype,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("content", content);
        map.put("phonetype",phonetype);
        map.put("systemtype",systemtype);
        NetUtils.post(context,  Constants.SERVER_HOST + "UserFeedback/", map, null, netCallBack, rspCls);
    }
    /***
    * 获取网络收藏
    * @param context
    * @param netCallBack
    * @param rspCls
    */
    public static void collectList(Context context,String username,int start,int pagesize,String token,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("username", username);
        map.put("start",start);
        map.put("pagesize",pagesize);
        map.put("token",token);
        NetUtils.post(context,  Constants.SERVER_HOST + "CollectList/", map, null, netCallBack, rspCls);
    }
    /***
     * 收藏清除所有地址
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void deleteAllCollect(Context context,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("token", Config.getUserToken());
        map.put("username",Config.getUserName());
        NetUtils.post(context,  Constants.SERVER_HOST + "DeleteAllCollect/", map, null, netCallBack, rspCls);
    }

    /***
     * 修改昵称
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void UpdateUserNickname(Context context,String nickname,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("token", Config.getUserToken());
        map.put("username",Config.getUserName());
        map.put("nickname",nickname);
        NetUtils.post(context,  Constants.SERVER_HOST + "UpdateUserNickname/", map, null, netCallBack, rspCls);
    }
    /***
     * 上传头像
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void UploadImage(Context context,String src_content,final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("token", Config.getUserToken());
        map.put("username",Config.getUserName());
        map.put("src_content",src_content);
        NetUtils.post(context,  Constants.SERVER_HOST + "UploadImage/", map, null, netCallBack, rspCls);
    }
}
